package cn.stylefeng.guns.modular.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.entity.ScheduleForm;
import cn.stylefeng.guns.modular.entity.ScheduleFrame;
import cn.stylefeng.guns.modular.service.ShareCommunityService;
import cn.stylefeng.guns.modular.wapper.MyScheduleFrameWrapper;
import cn.stylefeng.guns.modular.wapper.MyscheduleformWrapper;
import cn.stylefeng.roses.core.base.controller.BaseController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/shareCommunity")
public class ShareCommunityController extends BaseController {
    @Autowired
    private ShareCommunityService shareCommunityService;


    /**
     * 加载共享社区页面
     * @return
     */
    @RequestMapping("/loadShareCommunity")
    public String toSharecommunity(){
        return "sharedCommunity/sharedCommunity.html";
    }

    /**
     * 加载共享社区的数据
     * @return
     */
    @RequestMapping(value = "/loadShareCommunity" , method = RequestMethod.POST)
    @ResponseBody
    public JSONObject showSharecommunity(){
        //得到当前登陆者的信息

        List<ScheduleForm> scheduleForms= shareCommunityService.selectAllShareSform();

        List<ScheduleFrame> scheduleFrames= shareCommunityService.selectAllPublishSframe();


        Map<String,Object> map =new HashMap();
        map.put("scheduleForms",scheduleForms);
        map.put("scheduleFrames",scheduleFrames);

        JSONObject result = JSONObject.parseObject(JSON.toJSONString(map));
        System.out.println("===============result================="+result);
        return result;

    }



    /**
     * 重定向 共享社区-->所有的共享日程表
     * @return
     */
    @RequestMapping("/showShareSform")
    public String toShowShareSform(){
        return "/sharedcommunity/sharedSformCommunity.html";
    }

    /**
     * 显示所有共享的日程表
     */
    @RequestMapping(value = "/showShareSform" ,method = RequestMethod.POST)
    @ResponseBody
    public Object showShareSform(String keyword,String creatTime){
        System.out.println("=========1234=keyword======="+keyword+creatTime);
        if (keyword!=null&keyword!=""){
            keyword=keyword.trim();
        }
        Page<Map<String, Object>> sharedSforms =shareCommunityService.fuzzyShowShareSform(keyword,creatTime);
        Page wrapped = new MyscheduleformWrapper(sharedSforms).wrap();
        LayuiPageInfo layuiPageInfo =LayuiPageFactory.createPageInfo(wrapped);
        System.out.println("================================"+layuiPageInfo);
        return layuiPageInfo;

    }


    /**
     * 重定向 共享社区-->到已发布日程框架
     * @return
     */
    @RequestMapping("/showShareSframe")
    public String toshowShareSframe(){
        return "/sharedcommunity/sharedSframeCommunity.html";
    }


    /**
     * 显示所有已发布日程框架
     */
    @RequestMapping(value = "/showShareSframe" ,method = RequestMethod.POST)
    @ResponseBody
    public Object ShowDraftSframe(String keyword,String creatTime){
        System.out.println("=========1234=keyword======="+keyword+creatTime);
        if (keyword!=null&keyword!=""){
            keyword=keyword.trim();
        }
        Page<Map<String, Object>> sharedSframes =shareCommunityService.fuzzyShowShareSframe(keyword,creatTime);

        Page wrapped = new MyScheduleFrameWrapper(sharedSframes).wrap();
        LayuiPageInfo layuiPageInfo =LayuiPageFactory.createPageInfo(wrapped);
        System.out.println("================================"+layuiPageInfo);
        return layuiPageInfo;

    }

}
